// import { history } from 'umi';
import qs from 'qs';
import { removeStorage } from '@wowon/utils';
import { STORAGE_SAVE_ALWAYS } from '@/common/constant';
import getQuery from '@/utils/get-query';

const loginPath = '/user/login';
const loginPath = '/user/login';

/**
 * 退出登录，并且将当前的 url 保存
 */
const logout = () => {
  const query = getQuery();

  if (history.location.pathname.replace(BASE_PATH, '') !== loginPath && !query.redirect) {
  if (history.location.pathname.replace(BASE_PATH, '') !== loginPath && !query.redirect) {
    removeStorage(STORAGE_SAVE_ALWAYS, false);
    history.replace({
      pathname: loginPath,
      search: qs.stringify({ redirect: history.location.pathname }),
    });
  }
};

export default logout;
